package archer.framework.common.entity.validate;


import archer.framework.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Bean校验结果类
 *
 * @author christ
 * @date 2015/7/14
 */
public class ValidateResult {

    private boolean success = true;

    private List<String> errors = new ArrayList<String>();

    public static ValidateResult successInstance() {
        return new ValidateResult();
    }

    public static ValidateResult failInstance(List<String> errors) {
        ValidateResult result = new ValidateResult();
        result.success = false;
        result.errors = errors;
        return result;
    }

    public ValidateResult setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public ValidateResult addErrors(List<String> errors) {
        errors.addAll(errors);
        return this;
    }

    //----------------------getter--------------------

    /**
     * 校验成功
     *
     * @return
     */
    public boolean success() {
        return success;
    }

    /**
     * 校验失败
     *
     * @return
     */
    public boolean fail() {
        return !success;
    }

    /**
     * 错误集合
     *
     * @return
     */
    public List<String> errors() {
        return errors;
    }

    /**
     * 错误集合string输出
     *
     * @return
     */
    public String errorString() {
        return StringUtils.join(errors());
    }
}
